{include file="admin@public/header" /}
<body>
<div class="layui-fluid">
    <div class="layui-card" id="table">
        <div class="layui-card-body">
            <div>
                <button class="layui-btn" data-type="add">添加</button>
            </div>
            <table class="layui-table" id="test" lay-filter="test"></table>
        </div>
    </div>
</div>
<script type="text/html" id="powerTpl">
    {{#  if(d.level == 2){ }}
    &nbsp;&nbsp;丨---
    {{#  } else if(d.level == 3) { }}
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;丨---
    {{#  } }}
    {{d.power_name}}
</script>
<script type="text/html" id="typeTpl">
    {{#  if(d.type == 0){ }}
    菜单
    {{#  } else { }}
    按钮
    {{#  } }}
</script>
<script type="text/html" id="iconTpl">
    {{#  if(d.icon){ }}
    <i class="layui-icon layui-icon-{{d.icon}}"></i>
    {{#  } }}
</script>
<script type="text/html" id="optTpl">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script type="text/javascript">
    //搜索
    function search(curr) {
        window.location.reload();
    }


    layui.use(['laydate', 'table'], function() {
        var table = layui.table;
        table.render({
            elem: '#test'
            ,url: '/admin/power/lists'
            ,cols: [[ //表头
                {field: 'id', title: 'ID', width:60}
                ,{field: 'power_name', title: '权限名称', toolbar: '#powerTpl'}
                ,{field: 'uri', title: 'uri地址'}
                ,{field: 'icon', title: '图标', toolbar: '#iconTpl', width:100, align: 'center'}
                ,{field: 'type', title: '类型', toolbar: '#typeTpl', width:100}
                ,{field: 'sort', title: '排序', width:100}
                ,{field: 'update_time', title: '创建时间', width:155}
                ,{fixed: 'right', title:'操作', toolbar: '#optTpl', width:150}
            ]]
        });

        $('.layui-btn').click(function () {
            var type = $(this).data('type');
            if(type == 'add'){
                edit("{:url('/admin/power/add')}", '新增权限');
            }
        });

        //监听行工具事件
        table.on('tool(test)', function(obj){
            var data = obj.data;
            if(obj.event === 'del'){
                deleted("{:url('admin/power/delete')}", obj)
            } else if(obj.event === 'edit'){
                edit("{:url('/admin/power/edit/id/"+ data.id +"')}", '编辑' + data.power_name);
            }
        });
    });
</script>
</body>
</html>
